package com.cjh.mybatis08.executor.statement;

import com.cjh.mybatis08.executor.Executor;
import com.cjh.mybatis08.mapping.BoundSql;
import com.cjh.mybatis08.mapping.MappedStatement;
import com.cjh.mybatis08.session.ResultHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

/**
 * @Descripton 简单语句处理器（STATEMENT）
 * @Author cjh
 * @Date 2023/6/1 10:29
 */
public class SimpleStatementHandler extends BaseStatementHandler{

    public SimpleStatementHandler(Executor executor, MappedStatement mappedStatement,
                                  Object parameterObject, ResultHandler resultHandler, BoundSql boundSql) {
        super(executor, mappedStatement, parameterObject, resultHandler, boundSql);
    }

    @Override
    protected Statement instantiateStatement(Connection connection) throws SQLException {
        return connection.createStatement();
    }

    @Override
    public void parameterize(Statement statement) throws SQLException {
//        todo
    }

    @Override
    public <E> List<E> query(Statement statement, ResultHandler resultHandler) throws SQLException {
        String sql = boundSql.getSql();
        statement.executeQuery(sql);
        return resultSetHandler.handleResultSets(statement);
    }
}
